Object.defineProperty(exports, "__esModule", {
    value: !0
}), exports.default = diff;

var TYPE_OBJ = "[object Object]", TYPE_ARR = "[object Array]", getType = function(e) {
    return Object.prototype.toString.call(e);
}, PATH_REG_EXP = /^([a-zA-Z_$][\w$]*)((\[[a-zA-Z_$][\w$]*\])|\.[a-zA-Z_$][\w$]*)$/;

function setDiffResult(e, t, f) {
    e[t] = f;
}

function diffObj(e, t, f, r, i) {
    for (var n = 5 < arguments.length && void 0 !== arguments[5] ? arguments[5] : "", c = f; c--; ) {
        var s = t[c], o = e[s];
        void 0 === o && (o = null), "" === n && PATH_REG_EXP.test(s) ? setDiffResult(i, s, o) : diffFun(o, r[s], i, "".concat(n).concat(n ? "." : "").concat(s));
    }
}

function diffFun(e, t, f, r) {
    var i = getType(e);
    if (e !== t) {
        var n = getType(t);
        i === TYPE_OBJ ? n === TYPE_OBJ ? diffObject(e, t, f, r) : setDiffResult(f, r, e) : i === TYPE_ARR && n === TYPE_ARR ? diffArr(e, t, f, r) : setDiffResult(f, r, e);
    } else i !== TYPE_OBJ && i !== TYPE_ARR || setDiffResult(f, r, e);
}

function diffObject(e, t, f, r) {
    var i = Object.keys(e), n = i.length, c = Object.keys(t), s = c.length;
    if (n && s && s <= n) {
        for (var o = !1, u = s; u--; ) if (!Object.prototype.hasOwnProperty.call(e, c[u])) {
            o = !0;
            break;
        }
        o ? setDiffResult(f, r, e) : diffObj(e, i, n, t, f, r);
    } else {
        if (0 === n && 0 === s) return;
        setDiffResult(f, r, e);
    }
}

function diffArr(e, t, f, r) {
    var i = e.length, n = t.length;
    if (i && n && n <= i) for (var c = i; c--; ) diffFun(e[c], t[c], f, "".concat(r, "[").concat(c, "]")); else {
        if (0 === i && 0 === n) return;
        setDiffResult(f, r, e);
    }
}

function diff(e, t) {
    var f = Object.keys(e), r = f.length;
    if (e !== t && r && Object.keys(t).length) {
        var i = {};
        return diffObj(e, f, r, t, i), i;
    }
    return e;
}